<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>编辑页面</title>
</head>
<body>
<script type="text/html" id="form">
    <input type="hidden" name="id" value="{{= d.id }}" />
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
				<div class="layui-form-item">
    				<label class="layui-form-label" title="考试名称"> <text title="必填项" style="color:red;">*</text> 考试名称</label>
    				<div class="layui-input-block">
            			<input autocomplete="off" type="text" name="name" id="name" placeholder="请输入考试名称" value="{{=d.name}}" class="layui-input" lay-verify="required">
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="描述">描述</label>
    				<div class="layui-input-block">
            			<textarea name="description" id="description" placeholder="请输入描述" class="layui-textarea" lay-verify="">{{=d.description}}</textarea>
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="时长"> <text title="必填项" style="color:red;">*</text> 时长（分）</label>
    				<div class="layui-input-block">
            			<input autocomplete="off" type="text" name="duration" id="duration" placeholder="请输入时长" value="{{=d.duration}}" class="layui-input" lay-verify="required|number">
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="开始时间"> <text title="必填项" style="color:red;">*</text> 开始时间</label>
    				<div class="layui-input-block">
            			<input type="text" class="layui-input laydate"
            name="start_time" id="start_time" data-type="datetime"
            autocomplete="off" placeholder="请选择开始时间" value="{{=d.start_time}}" lay-verify="required" />
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="结束时间"> <text title="必填项" style="color:red;">*</text> 结束时间</label>
    				<div class="layui-input-block">
            			<input type="text" class="layui-input laydate"
            name="end_time" id="end_time" data-type="datetime"
            autocomplete="off" placeholder="请选择结束时间" value="{{=d.end_time}}" lay-verify="required" />
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="状态"> <text title="必填项" style="color:red;">*</text> 状态</label>
    				<div class="layui-input-block">
            			<!-- 隐藏域设置开关未选中时需要传递的参数值 -->
                        <input type="hidden" name="status" id="status-0" value="0" />
                        <input type="checkbox" name="status" id="status-1" lay-skin="switch" lay-text="启用|禁用" value="1" {{# if(1 == d.status){ }}checked="checked"{{# } }} />
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="允许组织id"> <text title="必填项" style="color:red;">*</text> 允许组织id</label>
    				<div class="layui-input-block">
            			<div class="xmSelect"
                            data-name="allow_org_ids"
                            data-sourceType="route"
                            data-source="/admin.org/index"
                            data-sourceTree="false"
                            data-paging="true"
                            data-radio="false"
                            data-valueField="id"
                            data-selected="{{=d.allow_org_ids}}"
							data-placeholder="请选择允许组织id"
							data-layVerify="required"
							data-direction="down"
                            ></div>
    				</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label" title="试卷"> <text title="必填项" style="color:red;">*</text> 选择试卷</label>
					<div class="layui-input-block">
						<div class="xmSelect"
							 data-name="paper_id"
							 data-sourceType="route"
							 data-source="/admin.exam.papers/index"
							 data-sourceTree="false"
							 data-paging="true"
							 data-radio="true"
							 data-valueField="id"
							 data-selected="{{=d.paper_id}}"
							 data-placeholder="请选择试卷"
							 data-layVerify="required"
							 data-direction="down"
						></div>
					</div>
				</div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="laytp-btn laytp-btn-primary laytp-btn-sm" lay-submit="" lay-filter="laytp-form">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="laytp-btn laytp-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</script>
<form class="layui-form" lay-filter="layui-form"></form>
<script>
    if(localStorage.getItem("staticDomain")){
        document.write("<link rel='stylesheet' href='" + localStorage.getItem("staticDomain") + "/component/laytp/css/laytp.css?v=" + localStorage.getItem("version") + "'>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/layui/layui.js?v=" + Date.now() + "'><\/script>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/laytp/layuiConfig.js?v=" + Date.now() + "'><\/script>");
    }else{
        document.write("<link rel='stylesheet' href='/static/component/laytp/css/laytp.css?v=" + localStorage.getItem("version") + "'>");
        document.write("<script src='/static/component/layui/layui.js?v=" + Date.now() + "'><\/script>");
        document.write("<script src='/static/component/laytp/layuiConfig.js?v=" + Date.now() + "'><\/script>");
    }
</script>
<script>
    layui.use(['laytp'],function(){
        let form = layui.form;
        let $ = layui.jquery;
        //获取参数ID
        var id = facade.getUrlParam('id');
        if(!id){
            facade.error('参数ID不能为空');
            return false;
        }

        //获取数据，渲染到对应的节点上
        facade.ajax({
            route: "/admin.exam/info",
            data: {id: id},
            successAlert: false,
            showLoading: true
        }).done(function(res){
            if(res.code === 0){
                layui.laytpl($("#form").html()).render(res.data,function(string){
                    $("form").html(string);
                    layui.laytpForm.render();
                    form.render();
                });
            }
        });

        form.on('submit(laytp-form)', function(data){
            var btnAnim = layui.button.load({elem:$(this)});
            try{
                data = facade.setEditorField(data);
            }catch (e) {
                facade.error(e);
                return false;
            }
            facade.ajax({
                route:'/admin.exam/edit',
                data:data.field
            }).done(function(res){
                if(res.code === 0){
                    parent.layui.layer.close(parent.layui.layer.getFrameIndex(window.name));//关闭当前页
                    parent.layui.table.reloadData("laytp-table");
                }
                btnAnim.stop();
            }).fail(function(){
                btnAnim.stop();
            });
            return false;
        });
    })
</script>
</body>
</html>